package com.just.springbootactuator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class SpringBootActuatorApplication {
    @Autowired
    StatusService statusService;

    /**
     * 注册端点的bean，通过/status可以访问端点
     */
    @Bean
    public Endpoint<String> status(){
        Endpoint<String> status=new StatusEndPoint();
        return status;
    }

    @GetMapping("/change")
    public String change(@RequestParam String status){
        statusService.setStatus(status);
        return "ok";
    }
    public static void main(String[] args) {
        SpringApplication.run(SpringBootActuatorApplication.class, args);
    }
}
